import 'package:flutter/material.dart';
import 'package:fortest/CustomPaintRoute.dart';
import 'package:fortest/FlutterReduxApp.dart';
import 'package:fortest/Indicator.dart';
import 'package:fortest/inheriteWidTest.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';

export 'CustomPaintRoute.dart';
import 'RefreshWidget.dart';
import 'Key.dart';

enum Actions {Increment}

int counterReducer(int state,dynamic action){
  if(action == Actions.Increment){
    return state+1;
  }
  return state;
}

void main() { 
  // final store = Store<int>(counterReducer,initialState:0);
  // runApp(
  //   FlutterReduxApp(
  //     title: 'flutter redux demo',
  //     store: store,
  //   )
  // );

  runApp(
    MyApp()
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      // home:MyHomePage(title:'title') 
       home:Screen()
      );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin{
  AnimationController controller;
  Animation<double> alpha;
  @override
  void initState(){
    super.initState();
    controller = AnimationController(duration: Duration(milliseconds: 2000),vsync: this); 
    final CurvedAnimation curve = CurvedAnimation(
      parent: controller,curve: Curves.elasticOut
    ); 
    alpha = Tween(begin: 0.0,end: 255.0).animate(curve)..addListener((){
      setState((){});
    })..addStatusListener((status){
      if(status == AnimationStatus.completed){
        controller.reverse();
      }else if(status == AnimationStatus.dismissed){
        controller.forward();
      }
    });
    controller.forward();
  }

  @override
  void dispose(){
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child:
      Container(
        width: alpha.value,
        height: alpha.value,
        decoration: BoxDecoration(
          color: Colors.redAccent
        ),
      )
    ));
  }
}

class Test extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return TestState();
  }
}
class TestState extends State<Test>{
  String pro;
  @override
  void didUpdateWidget(Widget oldWidget){
    super.didUpdateWidget(oldWidget);
  }

  @override
  Widget build(BuildContext context){
    return Text(
      ShareDataWidget.of(context).data.toString()
    );
  }

  @override
  void didChangeDependencies(){
    super.didChangeDependencies();
    print('依赖改变');
  }

}

class ShareDataWidget extends InheritedWidget{
  ShareDataWidget({
    @required this.data,
    Widget child
  }):super(child:child);

  final int data;

  static ShareDataWidget of(BuildContext context){
    return context.inheritFromWidgetOfExactType(ShareDataWidget);
  }

  @override
  bool updateShouldNotify(ShareDataWidget old){
    return old.data != data;
  }
}

